<?php


namespace App\Models;


use Lib\Model\Model;

class UserModel extends Model
{
    protected static $table = 'users';
    protected static $primary = 'id';
    protected static $fields = array('id', 'username', 'nickname', 'password', 'profile');

    public static function findByUsername($username)
    {
        $sql = "SELECT * FROM " . static::$table . " WHERE username = ? LIMIT 1";
        $result = static::executeSelect($sql, array('username' => $username), $error);
        if ($result === false) {
            throw new \ErrorException($error);
        }
        return count($result) > 0 ? $result[0] : null;
    }
}